package cn.wolfcode.luowowo.website.controller;

import cn.wolfcode.luowowo.common.util.AjaxResult;
import cn.wolfcode.luowowo.flight.query.FlightQueryObject;
import cn.wolfcode.luowowo.flight.service.IFlightSearchService;
import cn.wolfcode.luowowo.flight.util.FlightUtil;
import org.apache.dubbo.config.annotation.Reference;
import org.apache.http.util.EntityUtils;
import org.springframework.stereotype.Component;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Component
@RequestMapping("flight")
public class FlightController {
    @Reference
    private IFlightSearchService flightSearchService;

    /**
     * 航班主页
     *
     * @param qo
     * @param model
     * @return
     */
    @RequestMapping("")
    public String index(@ModelAttribute("qo") FlightQueryObject qo, Model model) {
        //查询国内前20热门城市
        model.addAttribute("hotFlights", flightSearchService.listByHotTop20(qo));
        //根据首字母查询城市
        model.addAttribute("initialA",flightSearchService.listByInitialABCDE());
        model.addAttribute("initialF",flightSearchService.listByInitialFGHJ());
        model.addAttribute("initialK",flightSearchService.listByInitialKLMNP());
        model.addAttribute("initialQ",flightSearchService.listByInitialQRSTW());
        model.addAttribute("initialX",flightSearchService.listByInitialXYZ());

        return "flight/index";
    }
    /**
     * 飞机订票接口
     * @return
     */
    @RequestMapping("search")
    @ResponseBody
    public Object search(FlightQueryObject qo) {
        AjaxResult result = flightSearchService.listByPortAndTime(qo);
        return result;
    }

}
